
* =================================
* Paper title: The political economy of energy access: Survey evidence from India on state intervention and public opinion
* Authors: Michael Aklin (Pitt), Patrick Bayer (Washington University in St. Louis), S.P. Harish (NYU) and Johannes Urpelainen (Columbia) 
* Energy Research & Social Science

* Last modified: November 13, 2015

* Data files used: PolEconIndia.dta
* System: Stata 13.1 on WIN 10

* Purpose: This do file replicates the main results of the paper
* =================================

*NB: Place all files in the same folder for paths to work properly

clear all
set more off, permanently

use "./PolEconIndia.dta"

* =================================
* 0. Preliminaries (variable creation and labels)
* =================================

gen age = .
replace age = 2013-birth_year
tab birth_year
tab age

gen govt_satisfied = .
label variable govt_satisfied "Govt Energy Policy Satisfaction (Sum)"
replace govt_satisfied = lpg_govt_satisfaction + kerosene_govt_satisfaction + gobar_govt_satisfaction + charcoal_govt_satisfaction + firewood_govt_satisfaction + dung_govt_satisfaction + lighting_satisfaction

factor lpg_govt_satisfaction kerosene_govt_satisfaction gobar_govt_satisfaction charcoal_govt_satisfaction firewood_govt_satisfaction dung_govt_satisfaction lighting_satisfaction, ipf factor(1)
rotate
predict factor_govt_satisfied
label variable factor_govt_satisfied "Govt Energy Policy Satisfaction (Factor)"

gen trust_politics = .
label variable trust_politics "Trust in Politics"
replace trust_politics = politician_trust + pm_trust + upcm_trust + govtofficial_trust + panchayat_trust
gen access_satisfaction = .

label variable access_satisfaction "Energy Access Satisfaction"
replace access_satisfaction  = lpg_satisfaction + kerosene_satisfaction + gobar_satisfaction + charcoal_satisfaction + firewood_satisfaction + dung_satisfaction

gen govt_intervention = .
label variable govt_intervention "Do you think that the government should intervene in the free market?"
replace govt_intervention = 0 if market_forces == 1
replace govt_intervention = 1 if market_forces == 0
tab market_forces govt_intervention
tab govt_intervention


* =================================
* 1. Summary statistics (Table 1)
* =================================

label variable govt_satisfied "Govt Energy Policy Satisfaction (Sum)"
label variable factor_govt_satisfied "Govt Energy Policy Satisfaction (Factor)"
label variable trust_politics "Trust in Politics"
label variable access_satisfaction "Energy Access Satisfaction"
label variable govt_intervention "Government Intervention"
label variable school_years "Schooling Years"
label variable electricity "Electrified Household"
label variable hhincome_monthly "Monthly Income"
label variable govt_caste "Government Caste"
label variable married "Married"
label variable candidate_proposal "Candidate Proposal"

estpost summarize govt_satisfied factor_govt_satisfied candidate_proposal govt_intervention trust_politics access_satisfaction school_years electricity hhincome_monthly govt_caste married

*esttab using "./summarystats.tex", booktabs cells("mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0)) count(fmt(0))") nonumber label replace

* =================================
* 2. Government energy policy satisfaction (Table 2)
* =================================

eststo clear
eststo: xi: reg govt_satisfied govt_intervention school_years i.village, robust
eststo: xi: reg govt_satisfied govt_intervention school_years trust_politics i.village, robust
eststo: xi: reg govt_satisfied govt_intervention school_years trust_politics electricity hhincome_monthly i.village, robust
eststo: xi: reg govt_satisfied govt_intervention school_years trust_politics electricity hhincome_monthly govt_caste married i.village, robust
eststo: xi: reg govt_satisfied govt_intervention school_years trust_politics electricity hhincome_monthly govt_caste married access_satisfaction i.village, robust

*esttab using "./govt_satisfaction.tex", booktabs label stats(N r2, labels(Observations) fmt(0 3)) nodepvars se(3) b(3) star(* 0.10 ** 0.05 *** 0.01) compress nomtitles nogaps replace drop(_cons _I*) note("Robust standard errors in parentheses.")


* =================================
* 3. Government energy policy satisfaction -- factor analysis (Table 3)
* =================================

eststo clear
eststo: xi: reg factor_govt_satisfied govt_intervention school_years i.village, robust
eststo: xi: reg factor_govt_satisfied govt_intervention school_years trust_politics i.village, robust
eststo: xi: reg factor_govt_satisfied govt_intervention school_years trust_politics electricity hhincome_monthly i.village, robust
eststo: xi: reg factor_govt_satisfied govt_intervention school_years trust_politics electricity hhincome_monthly govt_caste married i.village, robust
eststo: xi: reg factor_govt_satisfied govt_intervention school_years trust_politics electricity hhincome_monthly govt_caste married access_satisfaction i.village, robust

*esttab using "./factor_govt_satisfaction.tex", booktabs label stats(N r2, labels(Observations) fmt(0 3)) nodepvars se(3) b(3) star(* 0.10 ** 0.05 *** 0.01) compress nomtitles nogaps replace drop(_cons _I*) note("Robust standard errors in parentheses.")


* =================================
* 4. Government energy policy satisfaction by component -- (Table 4)
* =================================

eststo clear
eststo: xi: reg lpg_govt_satisfaction govt_intervention, robust
eststo: xi: reg kerosene_govt_satisfaction govt_intervention, robust
eststo: xi: reg gobar_govt_satisfaction govt_intervention, robust
eststo: xi: reg charcoal_govt_satisfaction govt_intervention, robust
eststo: xi: reg firewood_govt_satisfaction govt_intervention, robust
eststo: xi: reg dung_govt_satisfaction govt_intervention, robust
eststo: xi: reg lighting_satisfaction govt_intervention, robust

*esttab using "./ind_govt_satisfaction.tex", booktabs label stats(N, labels(Observations) fmt(0 3)) nodepvars se(3) b(3) star(* 0.10 ** 0.05 *** 0.01) compress nomtitles nogaps replace note("Robust standard errors in parentheses.")


* =================================
* 5. Energy voting -- (Table 5)
* =================================

tab govt_satisfied
gen revgovt_satisfied = 26 - govt_satisfied
tab revgovt_satisfied
rename revgovt_satisfied govt_satisfied_reverse
label variable govt_satisfied_reverse "Govt Energy Policy Dissatisfaction"


eststo clear
eststo: xi: probit candidate_proposal govt_satisfied_reverse i.village, robust
eststo: xi: probit candidate_proposal govt_satisfied_reverse access_satisfaction i.village, robust
eststo: xi: probit candidate_proposal govt_satisfied_reverse access_satisfaction market_forces i.village, robust
eststo: xi: probit candidate_proposal govt_satisfied_reverse access_satisfaction market_forces trust_politics i.village, robust

*esttab using "./energy_voting.tex", booktabs label stats(N, labels(Observations) fmt(0 3)) drop(_cons _I*) nodepvars se(3) b(3) star(* 0.10 ** 0.05 *** 0.01) compress nomtitles nogaps replace note("Robust standard errors in parentheses.")

* =================================
* 6. Voting margins plot (Figure 2)
* =================================

probit candidate_proposal govt_satisfied_reverse access_satisfaction market_forces trust_politics, robust
margins, at(govt_satisfied_reverse=(0(2)28))
marginsplot, xtitle("Government Dissatisfaction", size(3.5)) nolabels legend(off) title("Predicted Probability for Energy Voting", size(3)) ytitle("Predicted Probability", size(3.5)) xsca(titlegap(2)) ysca(titlegap(2)) ylabel(0(0.2)1) scheme(s2mono) graphregion(fcolor(white)) note("The above figure plots the predicted probability (along with 95% confidence intervals) of whether" "the respondent takes a candidate's proposals into account when voting. Government dissatisfaction" "levels are coded on a 0-28 scale. See the text for details.")



* =================================
* 7. Statisfaction by energy source (Figure 1)
* =================================

* Note this requires another data set
clear all
use "by_satisfaction_energy.dta"
graph hbar (asis) freq, over(satisfaction_categories) asyvars percent stack over(energy_source, relabel(01 "LPG" 02 "Biogas" 03 "Kerosene" 04 "Charcoal" 05 "Firewood" 06 "Dung" 07 "Lighting") sort(1) label(labsize(small))) bar(1, fcolor(black) fintensity(inten30)) bar(2, fcolor(black) fintensity(inten40)) bar(3,  fcolor(black) fintensity(inten50)) bar(4,  fcolor(black) fintensity(inten60)) bar(5,  fcolor(black) fintensity(inten70)) bar(6,  fcolor(black) fintensity(inten80)) lintensity(0) legend(label(1 "Very Unsatisfied") label(2 "Somewhat Unsatisfied") label(3 "Neutral") label(4 "Somewhat Satisfied") label(5 "Very Satisfied") size(vsmall) stack rows(1) region(style(outline) lcolor(white)) ) ytitle(Percent, size(vsmall)) nolabel title(Satisfaction Levels by Energy Source, color(black)) graphregion(color(white)) bgcolor(white)


